package com.briup;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class Test2 {
  public static void main(String[] args) throws IOException {
      String resource = "mybatis-config.xml";
      InputStream inputStream = Resources.getResourceAsStream(resource);
      //获取 SqlSessionFactory 对象
      SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
      //获取SqlSession对象
      SqlSession sqlSession = sessionFactory.openSession();
      try{
          //获取接口的实现对象
          //会为接口创建一个代理对象
          StuMapper mapper = sqlSession.getMapper(StuMapper.class);
          //调用接口的方法
          Student studentById = mapper.getStudentById(1);
          System.out.println(studentById);
      }finally{
          sqlSession.close();
      }
  }
}
